'''
https://leetcode.cn/problems/first-unique-number
'''
from collections import Counter, deque
from typing import List


class FirstUnique:

    def __init__(self, nums: List[int]):
        self.counter = counter = Counter(nums)
        self.q = deque()
        for k, v in counter.items():
            if v == 1:
                self.q.append(k)

    def showFirstUnique(self) -> int:
        q, counter = self.q, self.counter
        while q and counter[q[0]] > 1:
            q.popleft()
        return q[0] if q else -1

    def add(self, value: int) -> None:
        self.counter[value] += 1
        if self.counter[value] == 1:
            self.q.append(value)
